﻿





$(".keycope").on("click", function () {
    $('.copy_dom').html($(this).attr('aria-label'));
});

//微信点击站外链接弹出提示
$('.weixin-cover').click(function(){

    $('.weixin-tip').css('display','none');
    $('.tkl').css('display','block');
    $('.buy-wrapper').css('display','block');
    $('#myVideo').css('display','block');
});
$(".img .ui-link").click(function (event) {


    var _url = $(this).attr('href') ? $(this).attr('href') : $(this).data('href');
    var ua = navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        event.preventDefault();
        $('.weixin-tip').css('display','block');
        $('.tkl').css('display','none');
        $('.buy-wrapper').css('display','none');

        if($(this).data("href")){
            var _url = $(this).data("href");
        }else{
            var _url = $(this).attr("href");
        }
        if (/iphone|ipad|ipod/.test(ua)) {
            $('.wechat-brow').addClass('iosChat');
        } else if (/android|adr|linux/.test(ua)) {
            $('.wechat-brow').addClass('androidChat');
        }
        $('#myVideo').css('display','none');

    } else {
        // window.location.href = _url;
        // return false;
    }
    var videoDom = document.getElementById('myVideo');
    if(videoDom){
        videoDom.pause();
        $('.jp-video-play-icon').removeClass('video_playing');
        $('.jp-video-play-icon').removeClass('video_pausing');
        $('.jp-video-play-icon').addClass('video_pausing');
    }


});

$(function () {

    var kycopy = 1,ios = 1;
    function isIOS10() {
        //获取固件版本
        var getOsv = function () {
            var reg = /OS ((\d+_?){2,3})\s/;
            if (navigator.userAgent.match(/iPad/i) || navigator.platform.match(/iPad/i) || navigator.userAgent.match(/iP(hone|od)/i) || navigator.platform.match(/iP(hone|od)/i)) {
                var osv = reg.exec(navigator.userAgent);
                if (osv.length > 0) {
                    return osv[0].replace('OS', '').replace('os', '').replace(/\s+/g, '').replace(/_/g, '.');
                }
            }else{
                ios = 0;
            }
            return '';
        };
        var osv = getOsv();
        var osvArr = osv.split('.');
        //初始化显示ios9引导
        if (osvArr && osvArr.length > 0) {
            if (parseInt(osvArr[0]) >= 10) {
                return true
            }
        }
        return false
    }

    //ios版本

    if(isIOS10()){
        kycopy = 1;
    }else{
        kycopy = 0
    }
    //文字输入
    function iptNum(ths,sta) {
        if(sta) {
            taoKeyNum = ths.value;
        }
        if(ths.value != taoKeyNum) {
            ths.value = taoKeyNum;
        }
    }

    //不支持clip
    if(kycopy == 0 && ios == 1){
        $('.tkl-code').removeClass('yjfz_copy');
        $('.keycope').remove();
        document.addEventListener("selectionchange", function (e) {
            if (window.getSelection().anchorNode.parentNode.id == 'code1_ios' && document.getElementById('code1_ios').innerText != window.getSelection()) {
                var key = document.getElementById('code1_ios');
                window.getSelection().selectAllChildren(key);
            }
            if (window.getSelection().anchorNode.parentNode.id == 'code2_ios' && document.getElementById('code2_ios').innerText != window.getSelection()) {
                var key = document.getElementById('code2_ios');
                window.getSelection().selectAllChildren(key);
            }
        }, false);
    }else{

        if(ios == 1){
            var clipboard = new Clipboard('.keycope', {
                //动态设置复制内容
                target:function() {
                    // return trigger.getAttribute('aria-label');
                    return document.querySelector('.copy_dom');
                }
            });

            clipboard.on('success', function(e){
                $('.copy_dom').html('');

                e.trigger.innerHTML="已复制";
                e.trigger.style.background = "#c4c4c4";
                e.trigger.parentNode.style.borderColor = "#c4c4c4";
                e.clearSelection();
            });

            clipboard.on('error', function(e) {
                $('.copy_dom').html('');
                e.trigger.style.background = "#e73252";
                e.trigger.parentNode.style.borderColor = "#e73252";
                e.trigger.innerHTML="复制失败";
            });

            $('.yjfz_copy textarea').remove();
        }else{

            //一键复制!ios
            var dseClip = new Clipboard('.keycope', {
                text: function(trigger) {
                    return trigger.getAttribute('aria-label');
                }
            });
            dseClip.on('success', function(e) {
                e.trigger.style.background = "#c4c4c4";
                e.trigger.parentNode.style.borderColor = "#c4c4c4";
                e.trigger.innerHTML="已复制";
                e.clearSelection();
            });
            dseClip.on('error', function (e) {

                e.trigger.style.background = "#e73252";
                e.trigger.parentNode.style.borderColor = "#e73252";
                e.trigger.innerHTML="复制失败";
                e.clearSelection();
            });
        }

    }
});